<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .lights
        {
            display: flex;
        }

        .item {
            width: 50px;
            height: 50px;
            border-radius: 50px;
            margin-left:10px;
        }

        .red {
            background-color: red;
        }

        .green {
            background-color: green;
        }

        .yellow {
            background-color: yellow;
        }
    </style>
</head>

<body>
    <div class="lights">
        <div class="item red"></div>
        <div class="item green"></div>
        <div class="item yellow"></div>
    </div>
</body>

<script>
    let lights = document.querySelectorAll('.item');
    console.log(lights);
    let currentIndex = 0;
    setInterval(() => {
        lights.forEach(light => {
            light.style.opacity = 0;
        })
        let light = lights[currentIndex];
        currentIndex = (currentIndex + 1) % lights.length;
        light.style.opacity = 1;
    }, 1000)
</script>

</html>